//
// Created by Administrator on 2020/10/21.
//

#include "../../../lib/csp/include/cspApi.h"
#include "../../ccore/include/commDef.h"
#include "../../ccore/misc/include/misc.h"
#include "../include/memPools.h"

#ifdef O5G_TEST
static S_MemPoolAttr memPoolAttrTable4Amf[] =
{
    { MP_SIZE(128), MP_COUNT(64)},
    { MP_SIZE(256), MP_COUNT(64)},
    { MP_SIZE(512), MP_COUNT(32)},
    { MP_SIZE(1024), MP_COUNT(32)},
    { MP_SIZE(2048), MP_COUNT(16)},
    { MP_SIZE(4096), MP_COUNT(16)},
    { MP_SIZE(8192), MP_COUNT(8)},
    { MP_SIZE(16384), MP_COUNT(8)}
};

static S_MemPoolAttr memPoolAttrTable4Upf[] =
{
    { MP_SIZE(128), MP_COUNT(64)},
    { MP_SIZE(256), MP_COUNT(64)},
    { MP_SIZE(512), MP_COUNT(32)},
    { MP_SIZE(1024), MP_COUNT(32)},
    { MP_SIZE(2048), MP_COUNT(16)},
    { MP_SIZE(4096), MP_COUNT(16)},
    { MP_SIZE(8192), MP_COUNT(8)},
    { MP_SIZE(16384), MP_COUNT(8)}
};
#else
static S_MemPoolAttr memPoolAttrTable4Amf[] =
{
    { MP_SIZE(128), MP_COUNT(10240)},
    { MP_SIZE(256), MP_COUNT(8192)},
    { MP_SIZE(512), MP_COUNT(8192)},
    { MP_SIZE(1024), MP_COUNT(4096)},
    { MP_SIZE(2048), MP_COUNT(2048)},
    { MP_SIZE(4096), MP_COUNT(1024)},
    { MP_SIZE(8192), MP_COUNT(1024)},
    { MP_SIZE(16384), MP_COUNT(256)}
};

static S_MemPoolAttr memPoolAttrTable4Upf[] =
{
    { MP_SIZE(128), MP_COUNT(10240)},
    { MP_SIZE(256), MP_COUNT(8192)},
    { MP_SIZE(512), MP_COUNT(8192)},
    { MP_SIZE(1024), MP_COUNT(4096)},
    { MP_SIZE(2048), MP_COUNT(2048)},
    { MP_SIZE(4096), MP_COUNT(1024)},
    { MP_SIZE(8192), MP_COUNT(1024)},
    { MP_SIZE(16384), MP_COUNT(256)}
};
#endif

static S_MemPoolSetAttr memPoolSetAttrTable[] =
{
    { MEM_POOL_TYPE_MPMC, MP_MODE_POWER2, ARRAY_SIZE(memPoolAttrTable4Amf), memPoolAttrTable4Amf},
    { MEM_POOL_TYPE_MPMC, MP_MODE_POWER2, ARRAY_SIZE(memPoolAttrTable4Upf), memPoolAttrTable4Upf},
};
STATIC_ASSERT(ARRAY_SIZE(memPoolSetAttrTable) == CN_MP_TYPE_MAX);


int32_t CN_MP_Init(void)
{
    int32_t rc;

    rc = MPS_Init(memPoolSetAttrTable, ARRAY_SIZE(memPoolSetAttrTable));
    IF_RETURN(!=, O5G_RC_OK, rc, O5G_RC_ER, "CN_MP_Init() MPS_Init() error!\n");

    return O5G_RC_OK;
}

int32_t CN_MP_Final(void)
{
    MPS_Final();

    return O5G_RC_OK;
}

